package longcaisuyun.longcai.com.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;

import longcaisuyun.longcai.com.yiliubabalongcaisuyun.MyApplication;

/**
 * Created by Administrator on 2016/5/30.
 */
public class UtilsJz {
    /**
     * 判断两次密码是否相同,用于修改密码;
     *
     * @param et_passWord      密码控件
     * @param et_PassWordAgain 二次确认的密码控件
     * @return 1 新密码不能为空,2 两次输入的密码不相等 0 进行下一步
     */
    public static int isok(EditText et_passWord, EditText et_PassWordAgain) {
        if (TextUtils.isEmpty(et_passWord.getText().toString().trim()) || TextUtils.isEmpty(et_PassWordAgain.getText().toString().trim())) {
            return 1;
        } else if (!et_passWord.getText().toString().equals(et_PassWordAgain.getText().toString())) {
            return 2;
        } else {
            return 0;
        }
    }

    public static void xiuGaiMima(EditText jiuMima, EditText xinMiMa, EditText xinMiMagain, Context context) {
        if (!TextUtils.isEmpty(jiuMima.getText().toString().trim())) {
            if (MyApplication.myPreferences.readPassword().equals(jiuMima.getText().toString())) {
                switch (UtilsJz.isok(xinMiMa, xinMiMagain)) {
                    case 0:
                        Toast.makeText(context, "密码修改成功", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(context, "新密码不能为空", Toast.LENGTH_SHORT).show();
                        break;
                    case 2:
                        Toast.makeText(context, "两次输入的密码不一致", Toast.LENGTH_SHORT).show();
                        break;
                }
            } else {
                Toast.makeText(context, "输入的旧密码错误", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(context, "旧密码不能为空", Toast.LENGTH_SHORT).show();
        }

    }

}
